package com.miplus.ccrm.core.service.conf;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.miplus.ccrm.common.CmdResVo;
import com.miplus.ccrm.common.EnumRCode;
import com.miplus.ccrm.common.JPubUtils;
import com.miplus.ccrm.common.ServiceException;
import com.miplus.ccrm.core.controller.vo.conf.CmsEditVo;
import com.miplus.ccrm.core.controller.vo.conf.CmsReqVo;
import com.miplus.ccrm.core.controller.vo.conf.CmsResVo;
import com.miplus.ccrm.core.pojo.FiCommission;
import com.miplus.ccrm.core.mapper.FiCommissionMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
* @author pc
* @description 针对表【fi_commission】的数据库操作Service实现
* @createDate 2024-04-22 19:33:08
*/
@Service
public class FiCommissionServiceImpl extends MPJBaseServiceImpl<FiCommissionMapper, FiCommission>
    implements FiCommissionService{

    @Override
    public IPage<CmsResVo> commissionList(CmsReqVo paras)
    {
        return selectJoinListPage(new Page<>(paras.getPageNum(), paras.getPageSize()),
                CmsResVo.class,
                new MPJLambdaWrapper<FiCommission>()
                        .selectAs("fun_getnames('COLLECT.ODUE',t.overdue)", CmsResVo::getOverduedsc)
                        .selectAs("fun_getnames('COLLECT.ODUE',t.overdue2)", CmsResVo::getOverdue2dsc)
                        .selectAs("(select g.grpname from sys_grp g where g.grpid=t.grpid)",CmsResVo::getGrpname)
                        .selectAll(FiCommission.class)
                        .le(JPubUtils.IsNotEmpty(paras.getOverdue()),FiCommission::getOverdue,paras.getOverdue())
                        .ge(JPubUtils.IsNotEmpty(paras.getOverdue()),FiCommission::getOverdue2,paras.getOverdue())
                        .eq(JPubUtils.IsNotEmpty(paras.getGrpid()),FiCommission::getGrpid,paras.getGrpid())
                        .orderByAsc(FiCommission::getOverdue,FiCommission::getCmspercent)
        );
    }

    @Override
    public CmdResVo commissionUpdate(String $usrid, CmsEditVo paras)
    {
        FiCommission def=new FiCommission();
        BeanUtils.copyProperties(paras,def);
        def.setUpdt(new Date());
        def.setUpusr($usrid);
        int ret=baseMapper.updateById(def);
        return new CmdResVo(ret,def.getId().toString());
    }

    @Override
    public CmdResVo commissionInsert(String $usrid,CmsEditVo paras)
    {
        FiCommission def=new FiCommission();
        BeanUtils.copyProperties(paras,def);
        def.setUpdt(new Date());
        def.setUpusr($usrid);
        int ret=baseMapper.insert(def);
        return new CmdResVo(ret,def.getId().toString());
    }

    @Override
    public CmdResVo commissionDelete(Integer id)
    {
        int ret= baseMapper.deleteById(id);
        return new CmdResVo(ret,id.toString());
    }
}




